import http from '../util/http';

const getCustomerMessageList = data => http.getData(data, `/api/message/${data.appid}/pushes`);

const getCustomerMessage = data => http.getData(data, `/api/message/${data.appid}/pushes/${data.id}`);

const updateCustomerMessage = data => http.postData(data, `/api/message/${data.appid}/pushes/${data.id}/edit`);

const addCustomerMessage = data => http.postData(data, `/api/message/${data.appid}/pushes/create`);

const deleteCustomerMessage = data => http.postData({}, `/api/message/${data.appid}/pushes/${data.id}/delete`);

const getTemplateMessageList = data => http.getData(data, `/qingclass/templatepush/${data.appid}/list`);

const getTemplateMessage = data => http.getData(data, `/api/templatepush/${data.appid}/pushes/${data.id}`);

const updateTemplateMessage = data => http.postData(data, `/qingclass/templatepush/${data.appid}/update`);

const addTemplateMessage = data => http.postData(data, `/qingclass/templatepush/${data.appid}/save`);

const deleteTemplateMessage = data => http.postData({}, `/qingclass/templatepush/${data.appid}/delete/${data.id}`);


const getSubscribeMessageList = data => http.getData(data, `/api/message/${data.appid}/pushscripts`);

const getSubscribeMessage = data => http.getData(data, `/api/message/${data.appid}/pushscripts/${data.id}`);

const updateSubscribeMessage = data => http.postData(data, `/api/message/${data.appid}/pushscripts/${data.id}/edit`);

const addSubscribeMessage = data => http.postData(data, `/api/message/${data.appid}/pushscripts/create`);

const deleteSubscribeMessage = data => http.postData({}, `/api/message/${data.appid}/pushscripts/${data.id}/delete`);

const getQrcodeUrl = data => http.getData(data, '/api/oauth/codeURL');

const getOpenid = data => http.getData(data, '/api/oauth/getOpenid');


const previewMessage = data => http.postData(data, `/api/message/${data.appid}/preview`);
const previewTemplateMessage = data => http.postData(data, `/qingclass/templatepush/${data.appid}/preview`);
const uploadMpNewsMessage = data => http.postData(data, `/api/message/${data.appid}/uploadNews`);
const get48openIds = appid => http.getData({}, `/api/message/${appid}/48openIds`);

const getMpNewsByMediaId = ({ appid, mediaId }) => http.getData({ mediaId }, `/api/message/${appid}/mpNews`);
const getImageByMediaId = ({ appid, mediaId }) => http.getBlobData({ mediaId }, `/api/message/${appid}/image`);
const getVoiceByMediaId = ({ appid, mediaId }) => http.getBlobData({ mediaId }, `/api/message/${appid}/voice`);
const changeSubscribeMessageStatus = ({ appid, isActive, id }) => http.postData({ isActive }, `/api/message/${appid}/pushscripts/${id}/status`);
export default {
  getTemplateMessageList,
  getTemplateMessage,
  updateTemplateMessage,
  addTemplateMessage,
  deleteTemplateMessage,
  getCustomerMessageList,
  getCustomerMessage,
  updateCustomerMessage,
  addCustomerMessage,
  deleteCustomerMessage,
  getSubscribeMessageList,
  getSubscribeMessage,
  updateSubscribeMessage,
  addSubscribeMessage,
  deleteSubscribeMessage,
  previewMessage,
  previewTemplateMessage,
  uploadMpNewsMessage,
  get48openIds,
  getMpNewsByMediaId,
  getImageByMediaId,
  getVoiceByMediaId,
  changeSubscribeMessageStatus,
  getQrcodeUrl,
  getOpenid,
};
